//
//  BSSEnterpriseCertificationViewController.m
//  BSSMarket
//
//  Created by 传铎 on 2020/9/25.
//  Copyright © 2020 BSS. All rights reserved.
//

#import "BSSEnterpriseCertificationViewController.h"
#import "BSSBankListViewController.h"

#import "BSSEnterpriseCertificationBillTextFieldCell.h"
#import "BSSEnterpriseCertificationBillAddPhotoCell.h"
#import "BSSEnterpriseCertificationTextFieldCell.h"


#import "BSSEnterpriseCertificationModel.h"
#import "BSSUploadImagApi.h"

@interface BSSEnterpriseCertificationViewController ()<UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate,UITextViewDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate>
{
    BSSMarketAuthenticationModel *_authenticationModel;
}

@property (nonatomic, strong) NSArray                               *dataArr;
@property (nonatomic, strong) NSMutableArray                        *jsonArr;
@property (nonatomic, strong) UITableView                           *tableView;

@property (nonatomic, strong) UIImagePickerController               *imagePicker;

@property (nonatomic,   weak) UIButton                              *IDBtn;
///0 身份证正面，1 反面， 2 营业执照
@property (nonatomic, assign) NSInteger                             imgState;
@end

@implementation BSSEnterpriseCertificationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    self.title = @"企业/公司认证";
    self.view.backgroundColor = colorCode(@"ffffff");
    self.jsonArr = [NSMutableArray array];
    self.isEdit = YES;
    [self initParam];
    [self createUI];
    [self layoutUI];
}

- (void)initParam {
    //isEdit 1可以编辑 0不可以编辑
    if (_isStore) {
        NSString *authTypeName = @"个体工商户";
        if (!_isEnterprise) {
            authTypeName = @"个体工商户";
        }else{
            authTypeName = @"企业/公司";
        }
        self.dataArr = @[@{@"title":@"*企业名称：",@"placeholder":@"请输入企业名称",@"type":@"1",@"value":@"",@"isMandatory":@"1",@"key":@"storeName",@"isEdit":@"1"},@{@"title":@"*法人姓名：",@"placeholder":@"请输入法人姓名",@"type":@"1",@"value":@"",@"isMandatory":@"1",@"key":@"userName",@"isEdit":@"1"},@{@"title":@"*法人证件号：",@"placeholder":@"请输入法人证件号",@"type":@"6",@"value":@"",@"isMandatory":@"1",@"key":@"userIdno",@"isEdit":@"1"},@{@"title":@"认证类型：",@"placeholder":@"请选择认证类型",@"type":@"3",@"value":authTypeName,@"isMandatory":@"0",@"key":@"authType",@"isEdit":@"0"},@{@"title":@"*统一信用代码：",@"placeholder":@"请输入统一信用代码",@"type":@"1",@"value":@"",@"isMandatory":@"1",@"key":@"creditCode",@"isEdit":@"1"},@{@"title":@"工商注册号：",@"placeholder":@"请输入工商注册号",@"type":@"1",@"value":@"",@"isMandatory":@"0",@"key":@"businessReg",@"isEdit":@"1",@"maxLength":@"40"},@{@"title":@"纳税人识别号：",@"placeholder":@"请输入纳税人识别号",@"type":@"1",@"value":@"",@"isMandatory":@"0",@"key":@"taxRegister",@"isEdit":@"1",@"maxLength":@"40"},@{@"title":@"组织机构代码：",@"placeholder":@"请输入组织机构代码",@"type":@"1",@"value":@"",@"isMandatory":@"0",@"key":@"organizeCode",@"isEdit":@"1",@"maxLength":@"40"},@{@"title":@"*营业执照：",@"placeholder":@"请上传营业执照",@"type":@"4",@"value":@"",@"placeholderImage":@"market_enterprise_up",@"isMandatory":@"1",@"deleUrls":@"",@"key":@"licenseUrl",@"isEdit":@"1"},@{@"title":@"*法人身份证人像面：",@"placeholder":@"请上传法人身份证人像面",@"type":@"4",@"value":@"",@"placeholderImage":@"market_ID_front",@"isMandatory":@"1",@"deleUrls":@"",@"key":@"idFrontUrl",@"isEdit":@"1"},@{@"title":@"*法人身份证国徽面：",@"placeholder":@"请上传法人身份证国徽面",@"type":@"4",@"value":@"",@"placeholderImage":@"market_ID_back",@"isMandatory":@"1",@"deleUrls":@"",@"key":@"idBackUrl",@"isEdit":@"1"},@{@"title":@"*对公账户：",@"placeholder":@"请输入对公账户",@"type":@"5",@"value":@"",@"isMandatory":@"1",@"key":@"accountNo",@"isEdit":@"1",@"maxLength":@"20"},@{@"title":@"*开户银行：",@"placeholder":@"请选择开户银行",@"type":@"3",@"value":@"",@"isMandatory":@"1",@"key":@"parentBankName",@"isEdit":@"0"},@{@"title":@"*支行名称：",@"placeholder":@"请输入支行名称",@"type":@"1",@"value":@"",@"isMandatory":@"1",@"key":@"bankName",@"isEdit":@"1",@"maxLength":@"20"},@{@"title":@"*支行行号：",@"placeholder":@"请输入支行行号",@"type":@"2",@"value":@"",@"isMandatory":@"1",@"key":@"unionBank",@"isEdit":@"1",@"maxLength":@"20"}];
    }else{
        self.dataArr = @[@{@"title":@"*企业名称：",@"placeholder":@"请输入企业名称",@"type":@"1",@"value":@"",@"isMandatory":@"0",@"key":@"storeName",@"isEdit":@"0"},@{@"title":@"*法人姓名：",@"placeholder":@"请输入法人姓名",@"type":@"1",@"value":@"",@"isMandatory":@"0",@"key":@"userName",@"isEdit":@"0"},@{@"title":@"*法人证件号：",@"placeholder":@"请输入法人证件号",@"type":@"6",@"value":@"",@"isMandatory":@"0",@"key":@"userIdno",@"isEdit":@"0"},@{@"title":@"认证类型：",@"placeholder":@"请选择认证类型",@"type":@"3",@"value":@"一证",@"isMandatory":@"0",@"key":@"authType"},@{@"title":@"*统一信用代码：",@"placeholder":@"请输入统一信用代码",@"type":@"1",@"value":@"",@"isMandatory":@"0",@"key":@"creditCode",@"isEdit":@"0"},@{@"title":@"工商注册号：",@"placeholder":@"请输入工商注册号",@"type":@"1",@"value":@"",@"isMandatory":@"0",@"key":@"businessReg",@"isEdit":@"1",@"maxLength":@"40"},@{@"title":@"纳税人识别号：",@"placeholder":@"请输入纳税人识别号",@"type":@"1",@"value":@"",@"isMandatory":@"0",@"key":@"taxRegister",@"isEdit":@"1",@"maxLength":@"40"},@{@"title":@"组织机构代码：",@"placeholder":@"请输入组织机构代码",@"type":@"1",@"value":@"",@"isMandatory":@"0",@"key":@"organizeCode",@"isEdit":@"1",@"maxLength":@"40"},@{@"title":@"*营业执照：",@"placeholder":@"请上传营业执照",@"type":@"4",@"value":@"",@"placeholderImage":@"market_enterprise_up",@"isMandatory":@"0",@"deleUrls":@"",@"key":@"licenseUrl",@"isEdit":@"0"},@{@"title":@"*法人身份证人像面：",@"placeholder":@"请上传法人身份证人像面",@"type":@"4",@"value":@"",@"placeholderImage":@"market_ID_front",@"isMandatory":@"0",@"deleUrls":@"",@"key":@"idFrontUrl",@"isEdit":@"0"},@{@"title":@"*法人身份证国徽面：",@"placeholder":@"请上传法人身份证国徽面",@"type":@"4",@"value":@"",@"placeholderImage":@"market_ID_back",@"isMandatory":@"0",@"deleUrls":@"",@"key":@"idBackUrl",@"isEdit":@"0"},@{@"title":@"*对公账户：",@"placeholder":@"请输入对公账户",@"type":@"5",@"value":@"",@"isMandatory":@"1",@"key":@"accountNo",@"isEdit":@"1",@"maxLength":@"20"},@{@"title":@"*开户银行：",@"placeholder":@"请选择开户银行",@"type":@"3",@"value":@"",@"isMandatory":@"1",@"key":@"parentBankName",@"isEdit":@"0"},@{@"title":@"*支行名称：",@"placeholder":@"请输入支行名称",@"type":@"1",@"value":@"",@"isMandatory":@"1",@"key":@"bankName",@"isEdit":@"1",@"maxLength":@"20"},@{@"title":@"*支行行号：",@"placeholder":@"请输入支行行号",@"type":@"2",@"value":@"",@"isMandatory":@"1",@"key":@"unionBank",@"isEdit":@"1",@"maxLength":@"20"}];
    }
    
    [self.jsonArr addObjectsFromArray:[NSArray yy_modelArrayWithClass:[BSSEnterpriseCertificationModel class] json:self.dataArr]];
}

- (void)createUI {
    self.title = @"企业/公司认证";
    
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, __kScreenWidth__, __kSize(0))];
    headerView.backgroundColor = __kColor(248, 248, 248);
    self.tableView.tableHeaderView = headerView;
    
    
    
    [self.view addSubview:self.tableView];
    [self featchAuthentication];
}
#pragma mark - action
///获取认证信息
- (void)featchAuthentication {
    NSString *urls = @"";
    NSMutableDictionary *jsonDict = [NSMutableDictionary dictionary];
    if (_isEnterprise) {
        [jsonDict setValue:Format(_enterpriseStoreId) forKey:@"storeId"];
        urls = @"";
    }else{
        urls =@"";
    }
    
    BSSRequest *request = [[BSSRequest alloc] initWithURL:urls dic:jsonDict];
    [request startRequest:^(BSSRequestStatus requestStatus, NSString * _Nullable message, id  _Nullable responseObject) {
        if (requestStatus == BSSRequestStatusSuccess) {
            
            
            if (!IsEmpty(responseObject[@"data"])) {
                
                if (!IsEmpty(responseObject[@"data"][@"enterpriseCertifyDetail"])) {
                    NSDictionary * dict = responseObject[@"data"][@"enterpriseCertifyDetail"];
                    NSMutableArray *arr = [NSMutableArray array];
                    if (!IsEmpty(dict[@"creditCode"])) {
                        [arr addObject:@{@"key":@"creditCode",@"value":Format(dict[@"creditCode"])}];
                    }
                    if (!IsEmpty(dict[@"idBackUrl"])) {
                        [arr addObject:@{@"key":@"idBackUrl",@"value":Format(dict[@"idBackUrl"])}];
                    }
                    if (!IsEmpty(dict[@"idFrontUrl"])) {
                        [arr addObject:@{@"key":@"idFrontUrl",@"value":Format(dict[@"idFrontUrl"])}];
                    }
                    if (!IsEmpty(dict[@"licenseUrl"])) {
                        [arr addObject:@{@"key":@"licenseUrl",@"value":Format(dict[@"licenseUrl"])}];
                    }
                    if (!IsEmpty(dict[@"storeName"])) {
                        [arr addObject:@{@"key":@"storeName",@"value":Format(dict[@"storeName"])}];
                    }
                    if (!IsEmpty(dict[@"storeType"])) {
                        [arr addObject:@{@"key":@"storeType",@"value":Format(dict[@"storeType"])}];
                    }
                    if (!IsEmpty(dict[@"userIdno"])) {
                        [arr addObject:@{@"key":@"userIdno",@"value":Format(dict[@"userIdno"])}];
                    }
                    if (!IsEmpty(dict[@"userName"])) {
                        [arr addObject:@{@"key":@"userName",@"value":Format(dict[@"userName"])}];
                    }
                    
                    for (NSDictionary *dic in arr) {
                        for (BSSEnterpriseCertificationModel *model in self.jsonArr) {
                            if ([model.key isEqualToString:dic[@"key"]]) {
                                model.value = Format(dic[@"value"]);
                            }
                        }
                    }
                    
                }
                
            }
            
            [self.tableView reloadData];
        }else{
            [MBProgressHUD showText:message];
        }
    }];
}
- (void)layoutUI {
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(__kNavigationBarHeight__);
        make.left.right.mas_equalTo(self.view);
        make.bottom.mas_equalTo(-100);
    }];
    
    UIButton *submitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    submitBtn.backgroundColor = colorCode(@"#FE8300");
    [submitBtn setTitle:@"确认提交" forState:0];
    submitBtn.titleLabel.font = fontCount(16);
    [submitBtn setTitleColor:[UIColor whiteColor] forState:0];
    [self.view addSubview:submitBtn];
    submitBtn.layer.masksToBounds = YES;
    submitBtn.layer.cornerRadius = 4;
    [submitBtn addTarget:self action:@selector(submitClick) forControlEvents:UIControlEventTouchUpInside];
    [submitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_tableView.mas_bottom).offset(20);
        make.left.mas_equalTo(25);
        make.right.mas_equalTo(-25);
        make.height.mas_equalTo(40);
    }];
}
- (void)submitClick{
    
    for (int i = 0; i < _jsonArr.count; i ++) {
        BSSEnterpriseCertificationModel *model = _jsonArr[i];
        if ([model.isMandatory isEqualToString:@"1"]) {
            if (IsEmpty(model.value)) {
                [MBProgressHUD showText:model.placeholder];
                return;
            }
        }
    }
    NSString*deleUrls = @"";
    NSMutableDictionary *jsonDict = [NSMutableDictionary dictionary];
    for (BSSEnterpriseCertificationModel *model in _jsonArr) {
        [jsonDict setValue:model.value forKey:model.key];
        if ([model.type isEqualToString:@"4"]) {
            if (!IsEmpty(model.deleUrls)) {
                if (IsEmpty(deleUrls)) {
                    deleUrls = model.deleUrls;
                }else{
                    deleUrls = [NSString stringWithFormat:@"%@%@",deleUrls,model.deleUrls];
                }
            }
            
        }
    }
    [jsonDict setValue:_enterpriseStoreId forKey:@"storeId"];
    [jsonDict setValue:deleUrls forKey:@"deleteUrls"];
    NSString *urls = @"";
    if (_isEnterprise) {
        urls = @"";
    }else{
        urls = @"";
    }
    [MBProgressHUD showHUD];
    _baseRequest = [[BSSRequest alloc] initWithURL:urls dic:jsonDict];
    [_baseRequest startRequest:^(BSSRequestStatus requestStatus, NSString * _Nullable message, id  _Nullable responseObject) {
        [MBProgressHUD hideHUD];
        if (requestStatus == BSSRequestStatusSuccess) {
          
        }else{
            [MBProgressHUD showText:message];
        }
    }];
}
#pragma mark - UITableViewDelegate, UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    BSSEnterpriseCertificationModel *model = self.jsonArr[indexPath.row];
    if ([self.dataArr[indexPath.row][@"type"] isEqualToString:@"1"]||[self.dataArr[indexPath.row][@"type"] isEqualToString:@"2"]||[self.dataArr[indexPath.row][@"type"] isEqualToString:@"3"]) {
        BSSEnterpriseCertificationTextFieldCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BSSEnterpriseCertificationTextFieldCell" forIndexPath:indexPath];
        
        NSDictionary *dic = self.dataArr[indexPath.row];
        NSString *title = [dic valueForKey:@"title"];
        NSString *placeholder = [dic valueForKey:@"placeholder"];
        
        NSRange range = [title rangeOfString:@"*"];
        NSMutableAttributedString *outStr = [[NSMutableAttributedString alloc] initWithString:title];
        [outStr addAttributes:@{NSForegroundColorAttributeName : __kColor(193, 49, 54)} range:range];
        cell.titleLab.attributedText = outStr;
        cell.textField.placeholder = placeholder;
        if ([model.isEdit isEqualToString:@"1"]) {
            cell.textField.userInteractionEnabled = YES;
        }else{
            cell.textField.userInteractionEnabled = NO;
        }
        if ([self.dataArr[indexPath.row][@"type"] isEqualToString:@"1"]) {
            cell.textField.keyboardType = UIKeyboardTypeDefault;
        }else{
            cell.textField.keyboardType = UIKeyboardTypeNumberPad;
        }
        cell.model = model;
        return cell;
    }else if ([self.dataArr[indexPath.row][@"type"] isEqualToString:@"4"]){
        
        BSSEnterpriseCertificationBillAddPhotoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BSSEnterpriseCertificationBillAddPhotoCell" forIndexPath:indexPath];
        
        NSDictionary *dic = self.dataArr[indexPath.row];
        NSString *title = [dic valueForKey:@"title"];
        NSRange range = [title rangeOfString:@"*"];
        NSMutableAttributedString *outStr = [[NSMutableAttributedString alloc] initWithString:title];
        [outStr addAttributes:@{NSForegroundColorAttributeName : __kColor(193, 49, 54)} range:range];
        cell.titleLab.attributedText = outStr;
        

//
        if (_isStore) {
            if (!IsEmpty(model.value)) {
                cell.licenseDeleteBtn.hidden = NO;
            }
        }
        cell.model = model;

//        if (self.isEdit) {
//            if (indexPath.row == 7) {
//                [cell.licenseBtn sd_setImageWithURL:[NSURL URLWithString:Format(model.value)] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"market_enterprise_up"]];
//            }else if (indexPath.row == 8){
//                [cell.licenseBtn sd_setImageWithURL:[NSURL URLWithString:Format(model.value)] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"market_ID_front"]];
//            }else if (indexPath.row == 9){
//                [cell.licenseBtn sd_setImageWithURL:[NSURL URLWithString:Format(model.value)] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"market_ID_back"]];
//            }
//
//        }
//
        if ([model.isEdit isEqualToString:@"1"]) {
            cell.licenseBtn.userInteractionEnabled = YES;
        }else{
            cell.licenseBtn.userInteractionEnabled = NO;
        }
        return cell;
        
    }else if ([self.dataArr[indexPath.row][@"type"] isEqualToString:@"5"]||[self.dataArr[indexPath.row][@"type"] isEqualToString:@"6"]){
        
        BSSEnterpriseCertificationBillTextFieldCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BSSEnterpriseCertificationBillTextFieldCell" forIndexPath:indexPath];
        
        NSDictionary *dic = self.dataArr[indexPath.row];
        NSString *title = [dic valueForKey:@"title"];
        NSRange range = [title rangeOfString:@"*"];
        NSMutableAttributedString *outStr = [[NSMutableAttributedString alloc] initWithString:title];
        [outStr addAttributes:@{NSForegroundColorAttributeName : __kColor(193, 49, 54)} range:range];
        cell.titleLab.attributedText = outStr;
        if ([model.isEdit isEqualToString:@"1"]) {
            cell.textField.userInteractionEnabled = YES;
        }else{
            cell.textField.userInteractionEnabled = NO;
        }
        cell.model = model;
        return cell;
        
    }
    return nil;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    BSSEnterpriseCertificationModel *model = self.jsonArr[indexPath.row];
    if (indexPath.row == 3) {
//        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"请选择认证类型" message:nil preferredStyle: UIAlertControllerStyleActionSheet];
//        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel  handler:^(UIAlertAction * _Nonnull action) {
//            
//            
//        }];
//        NSArray *chooseArr = @[@"name",@""];
//        for (int i = 0;i< chooseArr.count;i++) {
//            NSString * str = chooseArr[i];
//            UIAlertAction *archiveAction1 = [UIAlertAction actionWithTitle:str style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//               
//            }];
//            [alertController addAction:archiveAction1];
//        }
//        
//        [alertController addAction:cancelAction];
//        [self presentViewController:alertController animated:YES completion:nil];
    }else if (indexPath.row == 12){
        WEAKSELF;
        BSSBankListViewController *vc = [[BSSBankListViewController alloc]init];
        vc.black = ^(NSString * _Nonnull bankName) {
            model.value = bankName;
            [weakSelf.tableView reloadData];
        };
        [self.navigationController pushViewController:vc animated:YES];
    }
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    
//    [self cornerRadiusCell:tableView willDisplayCell:cell forRowAtIndexPath:indexPath];
    
}



- (void)cornerRadiusCell:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    // 圆角弧度半径
    CGFloat cornerRadius = 5.f;
    
    // 设置cell的背景色为透明，如果不设置这个的话，则原来的背景色不会被覆盖
    cell.backgroundColor = UIColor.clearColor;
    
    // 创建一个shapeLayer
    CAShapeLayer *layer = [[CAShapeLayer alloc] init];
    CAShapeLayer *backgroundLayer = [[CAShapeLayer alloc] init]; //显示选中
    // 创建一个可变的图像Path句柄，该路径用于保存绘图信息
    CGMutablePathRef pathRef = CGPathCreateMutable();
    // 获取cell的size
    // 第一个参数,是整个 cell 的 bounds, 第二个参数是距左右两端的距离,第三个参数是距上下两端的距离
    CGRect bounds = CGRectInset(cell.bounds, 10, 0);
    
    // CGRectGetMinY：返回对象顶点坐标
    // CGRectGetMaxY：返回对象底点坐标
    // CGRectGetMinX：返回对象左边缘坐标
    // CGRectGetMaxX：返回对象右边缘坐标
    // CGRectGetMidX: 返回对象中心点的X坐标
    // CGRectGetMidY: 返回对象中心点的Y坐标
    
    // 这里要判断分组列表中的第一行，每组section的第一行，每组section的中间行
    
    // CGPathAddRoundedRect(pathRef, nil, bounds, cornerRadius, cornerRadius);

    if (indexPath.row == 0) {
        // 初始起点为cell的左下角坐标
        CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds));
        // 起始坐标为左下角，设为p，（CGRectGetMinX(bounds), CGRectGetMinY(bounds)）为左上角的点，设为p1(x1,y1)，(CGRectGetMidX(bounds), CGRectGetMinY(bounds))为顶部中点的点，设为p2(x2,y2)。然后连接p1和p2为一条直线l1，连接初始点p到p1成一条直线l，则在两条直线相交处绘制弧度为r的圆角。
        CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds), CGRectGetMidX(bounds), CGRectGetMinY(bounds), cornerRadius);
        CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
        // 终点坐标为右下角坐标点，把绘图信息都放到路径中去,根据这些路径就构成了一块区域了
        CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds));
        
    } else if (indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
        // 初始起点为cell的左上角坐标
        CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds));
        CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds), CGRectGetMidX(bounds), CGRectGetMaxY(bounds), cornerRadius);
        CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
        // 添加一条直线，终点坐标为右下角坐标点并放到路径中去
        CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds));
    } else {
        // 添加cell的rectangle信息到path中（不包括圆角）
        CGPathAddRect(pathRef, nil, bounds);
    }
    // 把已经绘制好的可变图像路径赋值给图层，然后图层根据这图像path进行图像渲染render
    layer.path = pathRef;
    backgroundLayer.path = pathRef;
    // 注意：但凡通过Quartz2D中带有creat/copy/retain方法创建出来的值都必须要释放
    CFRelease(pathRef);
    // 按照shape layer的path填充颜色，类似于渲染render
    // layer.fillColor = [UIColor colorWithWhite:1.f alpha:0.8f].CGColor;
    layer.fillColor = [UIColor whiteColor].CGColor;
    
    // view大小与cell一致
    UIView *roundView = [[UIView alloc] initWithFrame:bounds];
    // 添加自定义圆角后的图层到roundView中
    [roundView.layer insertSublayer:layer atIndex:0];
    roundView.backgroundColor = UIColor.clearColor;
    // cell的背景view
    cell.backgroundView = roundView;
    
}

#pragma mark - setter & getter

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.backgroundColor = __kColor(248, 248, 248);
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        _tableView.estimatedRowHeight = 200;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView registerClass:[BSSEnterpriseCertificationTextFieldCell class] forCellReuseIdentifier:@"BSSEnterpriseCertificationTextFieldCell"];
        [_tableView registerClass:[BSSEnterpriseCertificationBillAddPhotoCell class] forCellReuseIdentifier:@"BSSEnterpriseCertificationBillAddPhotoCell"];
        [_tableView registerClass:[BSSEnterpriseCertificationBillTextFieldCell class] forCellReuseIdentifier:@"BSSEnterpriseCertificationBillTextFieldCell"];
    }
    
    return _tableView;
}
- (UIImagePickerController *)imagePicker{
    if (!_imagePicker) {
        _imagePicker = [[UIImagePickerController alloc]init];
        _imagePicker.delegate = self;
        _imagePicker.allowsEditing = YES;
        _imagePicker.modalPresentationStyle = UIModalPresentationFullScreen;
    }
    return _imagePicker;
}


- (BSSMarketAuthenticationModel *)authenticationModel {
    if(!_authenticationModel){
        _authenticationModel = [BSSMarketAuthenticationModel new];
    }
    return _authenticationModel;
}

- (void)setAuthenticationModel:(BSSMarketAuthenticationModel *)authenticationModel {
    _authenticationModel = authenticationModel;
    
}

@end
